﻿@{
    ViewBag.Title = "添加卡片";
    Layout = "~/Areas/WeiXinAreas/Views/Shared/_LayoutWeui.cshtml";
}

<form id="form1">
    <div class="weui-cells__title">银行卡信息<span style="color:red;">（*只能填写本人名下的银行卡！）</span></div>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="" class="weui-label">卡&nbsp;&nbsp;&nbsp;&nbsp;号</label></div>
            <div class="weui-cell__bd">
                <input type="hidden" id="cardResultId" />
                <input type="hidden" value="@ViewData["userId"]" id="F_UserId" name="F_UserId" />
                <input class="weui-input" type="number" maxlength="19"  placeholder="请输入卡号" id="F_Account" name="F_Account" onblur="getBank()">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="" class="weui-label">银&nbsp;&nbsp;&nbsp;&nbsp;行</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" readonly  id="F_BankName" name="F_BankName">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="" class="weui-label">开户行</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" id="F_OpeningBank" name="F_OpeningBank" placeholder="请输入开户行">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="" class="weui-label">姓&nbsp;&nbsp;&nbsp;&nbsp;名</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" value="@ViewData["uName"] "   id="F_AccountName" name="F_AccountName" placeholder="请输入姓名">
            </div>
        </div>
    </div>
    <a href="javascript:submit();" class="weui-btn weui-btn_primary" style="margin-top:.5rem;background-color:#35a4fe;">提交<i class="weui-loading" style="display:none;"></i></a>
</form>
@section footScript
{
<script>
    function getBank()
    {
        if ($("#F_Account").val() != "") {
            $.ajax({
                url: "GetBank",
                data: { card: $("#F_Account").val() },
                dataType: 'json',
                type: 'post',
                success: function (_data) {
                   
                    $("#cardResultId").val(_data.result);
                    $("#F_BankName").val(_data.name);
                }
            });
        }
    }
    function submit() {
        if (yan() != false) {
            $(".weui-loading").show();
            $.ajax({
                url: "submitAccount",
                data: $("#form1").serialize(),
                dataType: 'json',
                type: 'post',
                success: function (_data) {
                    if (_data > 0) {
                        location.replace("Account?userId=@ViewData["userId"]");
                    } else {
                        $.alert("添加失败！");
                        $(".weui-loading").hide();
                    }
                }
            });
        }
    }
    function yan() {
        if ($("#F_Account").val() =="") {
            $.alert("请输入银行卡号!");
            return false;
        } 
        if ($("#cardResultId").val()==""||$("#cardResultId").val() == -1) {
            $.alert("请输入有效的银行卡号!");
            return false;
        }
        if ($("#F_OpeningBank").val() == '') {
            $.alert("请输入开户行!");
            return false;
        }
        if($("#F_AccountName").val()==""){
            $.alert("请输入账户名称!");
            return false;
        }
        //var haoma = $('#F_PhoneNumber').val();
        //if(haoma==""){
        //    $.alert("请输入手机号码!");
        //    return false;
        //}
        //if (!(/^1[34578]\d{9}$/.test(haoma))) {
        //    $.alert("手机号码有误，请重填!");
        //    return false;
        //}
        //var card = $("#F_IdCard").val();
        //if (card =="") {
        //    $.alert("请输入身份证号码!");
        //    return false;
        //}
        //if (!(/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(card))) {
        //    $.alert("身份证号码有误，请重填!");
        //    return false;
        //}
        return true;
    }
</script>
}